<?php
/**
 * @copyright: ©2024 永州 微聚 商 网络科技有限公司
 * @link: https://www.weiJuyunke.com
 */
namespace app\api\controller\consume;
use app\admin\model\ActivityConsumer;
use app\admin\model\StoreJoinActivity;
use app\common\controller\AdminController;
use think\App;

/**
 * @ControllerAnnotation(title="会员管理")
 */
class Stream extends AdminController
{

    use \app\admin\traits\Curd;

    /**
     * 字段排序
     *
     * @var array
     */
    protected $sort = [
        'create_time' => 'desc'
    ];

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\StreamLog();
    }

    /**
     * @NodeAnotation(title="列表")
     */
    public function index()
    {
        $request = $this->request;
        $param = $request->param();
        $page = input("page");
        $limit = input("limit");
        $where = [];

        if ($this->request->platform_id >0 ){
            $where[] = ['stream_log.platform_id','=',$this->request->platform_id];
        }
        if (isset( $param['telphone']) &&   $param['telphone'] ){
            $where[] = ['platformInfo.telphone|platformInfo.name','like','%'.$param['telphone'].'%'];
        }


        if (isset( $param['order_number']) &&   $param['order_number'] ){
            $where[] = ['stream_log.order_number','=',$param['order_number']];
        }

        if (isset( $param['user_name']) &&   $param['user_name'] ){
            $where[] = ['userInfo.telphone|nickname','like','%'.$param['user_name'].'%'];
        }
        if (isset( $param['store_telphone']) &&   $param['store_telphone'] ){
            $where[] = ['storeInfo.telphone|store_name','like','%'.$param['store_telphone'].'%'];
        }
        $count = $this->model->withJoin(['platformInfo','storeInfo','userInfo'], 'LEFT')
            ->where($where)
            ->count();
        $list = $this->model->withJoin(['platformInfo','storeInfo','userInfo'], 'LEFT')
            ->where($where)
            ->page($page, $limit)
            ->order($this->sort)
            ->select();

        $data['order_amount'] = $this->model->withJoin(['platformInfo','storeInfo','userInfo'], 'LEFT')->sum('order_amount');


        $data['system_handling_fee'] = $this->model->withJoin(['platformInfo','storeInfo','userInfo'], 'LEFT')->sum('system_handling_fee');

        $data['platform_application_fee'] = $this->model->withJoin(['platformInfo','storeInfo','userInfo'], 'LEFT')->sum('platform_handling_fee');


        return msg([
            'list' => $list,
            'data' => $data,
            'count' => $count
        ], 0, "success");
    }













}